<?php
namespace Todo\Model\Rate;

use Todo\Model\BaseModel;

class ResultsModel extends BaseModel
{
    protected $order = 'id DESC';

    public $tableName = 'rate_results';

    public $_validate = array(
        array('project_id', 'require', '请选择项目'),
        array('user_id', 'require', '必须有被评人'),
        array('name', 'require', '必须有被评人')
    );
    
    protected $_auto = array(
        array('tnt_id', 'auto_tnt', self::MODEL_INSERT, 'function')
    );
    
    /**
     * 导出Excel
     * @param $list array 数据列表
     * @param $excel ExcelUtil Excel操作对象
     */
    public function exports($list, $excel){
        $title = array(
            'project'=>'项目',
            'name'=>'姓名',
            'number'=>'工号/学号',
            'score'=>'分数',
            'sort'=>'排名'
        );
        foreach ($list as &$row){
            if($row['project_id']) $row['project'] = D('Todo/Rate/project')->keyFind($row['project_id'], 'title');
            else $row['project'] = '';

            $row['number'] = D('Todo/Sys/UserIdentity')->where(array('user_id'=>$row['user_id']))->getField('param');
        }
        $excel->exportExcel("评价结果", $title, $list);
    }
}